package com.test;

/*
public class Example01 {
    public static void main(String[] args) throws Exception {
        //创建一个空的字符串
        String str1 = new String();
        //创建一个内容abcd的字符串
        String str2 = new String("abcd");
        //创建一个字符数组
        char[] charArray = new char[]{'D', 'E', 'D'};
        String str3 = new String(charArray);
        //创建一个字节数组
        byte[] arr = {97, 98, 99};
        String str4 = new String(arr);
        System.out.println("a" + str1 + "b");
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(str4);

    }
}


 */


/*
public class Example01 {
    public static void main(String[] args) {
        String s = "abababababcccccab";
        //获取字符串长度,即字符个数
        System.out.println("字符串长度:"+s.length());
        System.out.println("字符串的第一个字符:"+s.charAt(0));
        System.out.println("字符c第一次出现的位置:"+s.indexOf('c'));
        System.out.println("字符c最后一次出现的位置:"+s.lastIndexOf('c'));
        System.out.println("字符串ab最后一次出现的位置:"+s.lastIndexOf("ab"));
    }
}


 */


/*
public class Example01 {
    public static void main(String [] args){
        String str="abCD";
        System.out.print("将字符串转为字符数组后的结果:");
        char[] charArray=str.toCharArray();     //字符串转换成字符数组
        for(int i=0;i<charArray.length;i++){
            if(i!=charArray.length-1){
                //如果不是数组的最后一个元素,在元素尾加逗号
                System.out.print(charArray[i]+",");
            }else{
                System.out.println(charArray[i]);
            }
        }
        System.out.println("将int值转换成String类型之后的结果:"+String.valueOf(12));
        System.out.println("将字符串转换成大写之后的结果:"+str.toUpperCase());
        System.out.println("将字符串转换成小写之后的结果:"+str.toLowerCase());
    }
}


 */


/*
public class Example01 {
    public static void main(String [] args){
        String s="itcast";
        //字符串替换操作
        System.out.println("将it替换成cn.it的结果:"+s.replace("it","cn.it"));
        //字符串去除空格操作
        String s1="  i  t  c    a  s  t  ";
        System.out.println("去除字符串两端的空格的结果:"+s1.trim());
        System.out.println("去掉字符串中所有空格后的结果:"+s1.replace(" ",""));
    }
}

 */


/*
public class Example01 {
    public static void main(String [] args){
        String s1="String";
        String s2="string";
        String s3="strlng";
        System.out.println("判断s1字符串对象是否以Str开头:"
                + s1.startsWith("Str"));
        System.out.println("判断是否包含字符串tri:"+s1.contains("tri"));
        System.out.println("判断字符串是否为空:"+s1.isEmpty());
        System.out.println("判断s1和s2内容是否相同:"+s1.equalsIgnoreCase(s2));
        System.out.println("判断s1和s3内容是否相同:"+s1.equalsIgnoreCase(s3));
        System.out.println("按对应字符的Unicode比较s1和s2的大小："+s1.compareTo(s2));
        //按字典顺序比较两个字符串，忽略大小写差异。
        System.out.println("按对应字符的Unicode比较s1和s2的大小："+s1.compareToIgnoreCase(s2));
    }
}

 */



/*
public class Example01 {
    public static void main(String[] args){
        String str1="石家庄-武汉-哈尔滨";
        //字符串截取
        System.out.println("从第5个字符截取到末尾的结果:"+ str1.substring(4));
        System.out.println("从第5个字符截取到第6个字符的结果:"+str1.substring(4,6));
        //字符串分割
        System.out.print("分割后的字符串数组中的元素依次是:");
        String[] strArray=str1.split("-");
        for(int i=0;i<strArray.length;i++){
            if(i!=strArray.length-1){
                System.out.print(strArray[i]+",");
            }else{
                System.out.println(strArray[i]);
            }
        }
    }
}


 */

/*
public class Example01 {
    public static void main(String [] args){
        String s="itcast";
        System.out.println(s.charAt(3));
//        System.out.println(s.charAt(8));
        //.charAt()
        //返回指定索引处的char值。索引的取值范围是0 ~ length() - 1。序列的第一个字符值位于索引0处，下一个位于索引1处，以此类推，对于数组索引。
        //如果索引指定的char值是代理值，则返回代理值。
    }
}

 */



/*
public class Example01 {
    public static void main(String[] args) {
        System.out.println("------- 1.添加 -------");
        add();
        System.out.println("------- 2.删除 -------");
        remove();
        System.out.println("------- 3.修改 -------");
        alter();
        System.out.println("------- 4.截取 -------");
        sub();
    }

    public static void add() {
        StringBuffer sb = new StringBuffer();     //定义一个字符串缓冲区
        sb.append("abcdefg");       //在末尾添加字符串
        sb.append("hij").append("klmn");        //连续调用append()方法添加字符串
        System.out.println("append添加结果:" + sb);
        sb.insert(2, "123");     //在指定位置插入字符串
        System.out.println("insert添加结果:" + sb);
    }

    public static void remove() {
        StringBuffer sb = new StringBuffer("abcdefg");
        sb.delete(1, 5);         //指定范围删除
        System.out.println("删除指定位置的结果:" + sb);
        sb.deleteCharAt(2);     //指定位置删除
        System.out.println("删除指定位置的结果:" + sb);
        sb.delete(0, sb.length());
        System.out.println("清空缓冲区结果:" + sb);
    }

    public static void alter() {
        StringBuffer sb = new StringBuffer("abcdef");
        sb.setCharAt(1, 'p');
        System.out.println("修改指定位置字符结果:" + sb);
        sb.replace(1, 3, "qq");
        System.out.println("替换指定位置字符串结果:" + sb);
        System.out.println("字符串翻转结果:" + sb.reverse());
    }
    public static void sub(){
        StringBuffer sb=new StringBuffer();
        System.out.println("获取sb的初始容量"+sb.capacity());
        sb.append("itcast123");
        System.out.println("append添加结果:"+sb);
        System.out.println("截取第7~9个字符:"+sb.substring(6,9));
    }
}
 */

/*
public class Example01 {
    public static void main(String[] args) {
        int[] fromArray = {10, 11, 12, 13, 14, 15};     //src源数组
        int[] toArray = {20, 21, 22, 23, 24, 25, 26};       //dest目标数组
        System.arraycopy(fromArray,2,toArray,3,4);
        System.out.println("复制后的数组元素为:");
        for(int i=0;i<toArray.length;i++){
            System.out.print(toArray[i]+" ");
        }
    }
}
 */

/*
public class Example01 {
    public static void main(String[] args){
        long startTime=System.currentTimeMillis();      //循环开始是的当前时间
        int sum=0;
        for(int i=0;i<1000000000;i++){
            sum+=1;
        }
        long endTime=System.currentTimeMillis();        //循环结束后的当前时间
        System.out.println("程序运行的时间为:"+(endTime-startTime)+"ms");
    }
}

 */

/*
import java.util.Enumeration;
import java.util.Properties;

public class Example01 {
    public static void main(String[] args) {
        //获取当前系统属性
        Properties properties = System.getProperties();
        //获取所有系统属性的key,返回Enumerate对象
        Enumeration propertyNames = properties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            //获取系统属性的键key
            String key = (String) propertyNames.nextElement();
            //获取当前键key对应的值value
            String value=System.getProperty(key);
            System.out.println(key+"---->"+value);
        }
    }
}

 */
/*
class Person {
    private String name;
    private int age;

    public Person() {

    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    public void finalize() throws Throwable{
        //'finalize()' should have protected access, not public
        System.out.println("对象被释放-->"+this);
    }
}

public class Example01 {
    public static void main(String[] args) {
        //下面是创建Person对象
        Person p=new Person("张三",20);
        p=null;
        System.gc();
        for(int i=0;i<1000000;i++){
            //为了延长程序运行时间,执行空循环
        }
    }
}

 */

/*
public class Example01 {
    public static void main(String[] args) {
        Runtime rt = Runtime.getRuntime();        //创建Runtime对象
        System.out.println("处理器的个数:" + rt.availableProcessors() + "个");
        System.out.println("空闲内存数量:" + rt.freeMemory() / 1024 / 1024 + "MB");
        System.out.println("最大可用内存数量:" + rt.maxMemory() / 1024 / 1024 + "MB");
        System.out.println("内存总容量:" + rt.totalMemory() / 1024 / 1024 + "MB");
    }
}

 */

/*
import java.io.IOException;

public class Example01 {
    public static void main(String[] args)throws IOException{
        Runtime rt=Runtime.getRuntime();        //创建Runtime实例对象
        rt.exec("notepad.exe");     //调用exec()方法
        //打开了记事本
    }
}

 */

/*
public class Example01 {
    public static void main(String[] args){
        System.out.println("计算-10的绝对值:"+Math.abs(-10));
        System.out.println("求大于5.6的最小整数:"+Math.ceil(5.6));
        System.out.println("求大于-5.6的最小整数:"+Math.ceil(-5.6));
        System.out.println("求小于4.2的最大整数:"+Math.floor(4.2));
        System.out.println("求小于-4.2的最大整数:"+Math.floor(-4.2));
        System.out.println("对-4.6进行四舍五入: " + Math.round(-4.6));
        System.out.println("求2.1和-2.1中的较大值: " + Math.max(2.1, -2.1));
        System.out.println("生成一个大于等于0.0小于1.0的随机数"+Math.random());
        System.out.println("计算1.57的正弦结果: "+Math.sin(1.57));
        System.out.println("计算4的开平方的结果: "+Math.sqrt(4));
        System.out.println("计算指数函数2的3次方的值: "+Math.pow(2, 3));

    }
}

 */

/*
import java.util.Random;


import java.util.Random;

public class Example01 {
    public static void main(String args[]) {
        Random random = new Random(); // 不传入种子
        // 随机产生10个[0,100)之间的整数
        for (int x = 0; x < 5; x++) {
            System.out.println(random.nextInt(0,100));
        }
    }
}
 */

/*
import java.util.Random;

public class Example01 {
    public static void main(String args[]) {
        Random r = new Random(13); // 创建对象时传入种子
        // 随机产生10个[0,100)之间的整数
        for (int x = 0; x < 10; x++) {
            System.out.println(r.nextInt(100));
        }
    }
}

 */

/*
import java.util.Random;

public class Example01 {
    public static void main(String[] args){
        Random r=new Random();      //创建Random实例对象
        System.out.println("生成boolean类型的随机数:"+r.nextBoolean());
        System.out.println("生成float类型的随机数:"+r.nextFloat());
        System.out.println("生成double类型的随机数"+r.nextDouble());
        System.out.println("生成int类型的随机数:"+r.nextInt());
        System.out.println("生成0~100之间int类型的随机数:"+r.nextInt(0,100));
        System.out.println("生成long类型的随机数:"+r.nextLong());
    }
}

 */

/*
import java.math.BigInteger;

public class Example01 {
    public static void main(String[] args){
        BigInteger bi1=new BigInteger("123456789");
        BigInteger bi2=new BigInteger("987654321");
        System.out.println("bi2与bi1的和:"+bi2.add(bi1));
        System.out.println("bi2与bi1的差:"+bi2.subtract(bi1));
        System.out.println("bi2与bi1的积:"+bi2.multiply(bi1));
        System.out.println("bi2与bi1的商:"+bi2.divide(bi1));
        System.out.println("bi2与bi1之间的较大值:"+bi2.max(bi1));
        System.out.println("bi2与bi1之间的较小值:"+bi2.min(bi1));
        //创建BigInteger数组接受bi2除以bi1的商和余数
        BigInteger result[] =bi2.divideAndRemainder(bi1);
        System.out.println("bi2除以bi1的商:"+result[0]+"\n"+"bi2除以bi1的余数:"+result[1]);

    }
}

 */


/*
import java.util.Date;

public class Example01 {
    public static void main(String[] args) {
        Date date1 = new Date();
        Date date2 = new Date(System.currentTimeMillis() + 1000);
        System.out.println(date1);
        System.out.println(date2);
    }
}

 */

/*
public class Example01 {
    public static void main(String[] args){
        Calendar calendar=Calendar.getInstance();
        int year=calendar.get(Calendar.YEAR);
        int month= calendar.get(Calendar.MONTH)+1;
        int date=calendar.get(Calendar.DATE);
        int hour=calendar.get(Calendar.HOUR);
        int minute=calendar.get(Calendar.MINUTE);
        int second=calendar.get(Calendar.SECOND);
        System.out.println("当前时间:"+year+"年"+month+"月"+date+"日"+hour+"时"+minute+"分"+second+"秒");
    }
}

 */

/*
import java.util.Calendar;

public class Example01 {
    public static void main(String[] args){
        //获取表示当前时间的Calendar对象
        Calendar calendar=Calendar.getInstance();
        //设置指定日期
        calendar.set(2020,02,02);
        //根据日历规则在给定的日历字段中添加或减去指定的时间量。例如，要从日历的当前时间减去5天，可以调用:add(calendar)。DAY_OF_MONTH, 5)。
        calendar.add(Calendar.DAY_OF_MONTH,100);
        int year=calendar.get(Calendar.YEAR);
        int month=calendar.get(Calendar.MONTH)+1;
        int date=calendar.get(Calendar.DATE);
        System.out.println("计划竣工日期为:"+year+"年"+month+"月"+date+"日");
    }
}

 */
/*
public class Example01 {
    public static void main(String[] args) {
        Instant now = Instant.now();
        System.out.println("从系统获取的当前时刻:" + now);
        Instant instant = Instant.ofEpochMilli(1000 * 60 * 60 * 24);
        System.out.println("计算机元年增加1000*60*60*24毫秒后为:" + instant);
        Instant instant1 = Instant.ofEpochSecond(60 * 60 * 24);
        System.out.println("计算机元年增加60*60*24秒数后为:" + instant1);
        System.out.println("获取的秒值为："
                + Instant.parse("2007-12-03T10:15:30.44Z").getEpochSecond());
        System.out.println("获取的纳秒值为："
                + Instant.parse("2007-12-03T10:15:30.44Z").getNano());
        System.out.println("从时间对象获取的Instant实例为：" +
                Instant.from(now));
    }
}


 */


/*
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Example01 {
    public static void main(String [] args){
        LocalDate now=LocalDate.now();
        LocalDate of=LocalDate.of(2015,12,12);
        System.out.println("1. LocalDate的获取及格式化的相关方法-------");
        System.out.println("从LocalDate实例获取当前的年份是:"+now.getYear());
        System.out.println("从LocalDate实例获取当前的月份是:"+now.getMonthValue());
        System.out.println("从LocalDate实例获取当天本月的第几天:"+now.getDayOfMonth());
        System.out.println("将获取到的LocalDate实例格式化后是:"+now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
        System.out.println("2. LocalDate判断的相关方法");
        System.out.println("判断日期of是否在now之前："+of.isBefore(now));
        System.out.println("判断日期of是否在now之后："+of.isAfter(now));
        System.out.println("判断日期of和now是否相等："+now.equals(of));
        System.out.println("判断日期of是否是闰年："+ of.isLeapYear());
        System.out.println("3. LocalDate解析以及加减操作的相关方法---------");
        String dateStr="2020-02-01";
        System.out.println("把日期字符串解析成日期对象的结果是："+LocalDate.parse(dateStr));
        System.out.println("将LocalDate实例年份加1后的结果是："+now.plusYears(1));
        System.out.println("将LocalDate实例天数减10后的结果是："+now.minusDays(10));
        System.out.println("将LocalDate实例的年份设置为2014后的结果是：" +now.withYear(2014));
    }
}

 */

/*
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class Example01 {
    public static void main(String[] args){
        LocalTime time=LocalTime.now();
        LocalTime of=LocalTime.of(9,23,22);
        System.out.println("从LocalTime获取的小时:"+time.getHour());
        System.out.println("将过去到的LocalTime实例格式化:"+time.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        System.out.println("判断时间of是否在now之前："+of.isBefore(time));
        System.out.println("将时间字符串解析为时间对象后:"+LocalTime.parse("12:15:30"));
        System.out.println("从LocalTime获取当前时间,不包含毫秒数:"+time.withNano(0));
    }
}
 */

/*
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class Example01 {
    public static void main(String[] args) {
        LocalTime now = LocalTime.now();
        now=now.withNano(0);
        System.out.println("获取的当前日期时间:" + now);
        DateTimeFormatter of_pattern = DateTimeFormatter.ofPattern("HH时mm分ss秒");
        System.out.println("格式化后的日期时间为:"+now.format(of_pattern));
    }
}

 */

/*
import java.time.Duration;
import java.time.LocalTime;

public class Example01 {
    public static void main(String[] args){
        LocalTime start=LocalTime.now();
        LocalTime end=LocalTime.of(13,13,13);
        Duration duration= Duration.between(start,end);
        System.out.println("时间间隔为:"+duration.toNanos()+"纳秒");
        System.out.println("时间间隔为:"+duration.toMillis()+"毫秒");
        System.out.println("时间间隔为:"+duration.toHours()+"小时");
    }
}

 */


/*
import java.time.LocalDate;
import java.time.Period;

public class Example01 {
    public static void main(String[] args) {
        LocalDate birthday = LocalDate.of(2018, 12, 12);
        LocalDate now = LocalDate.now();
        //计算两个日期的间隔
        Period between = Period.between(birthday, now);
        System.out.println("时间间隔为" + between.getYears() + "年");
        System.out.println("时间间隔为" + between.getMonths() + "月");
        System.out.println("时间间隔为" + between.getDays() + "天");
    }
}

 */